#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/Swap.h>
#pragma unmanaged 
#include <ql\instruments\vanillaswap.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#define STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IVanillaSwap
	public ref class CVanillaSwap  : 
            public CSwap,
            public Cephei::QL::Instruments::IVanillaSwap
	{
	protected: 
		boost::shared_ptr<QuantLib::VanillaSwap>* _ppVanillaSwap;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::VanillaSwap>* _phVanillaSwap;
#endif
		Object^ _VanillaSwapOwner;     // reference to object that manages the storage for this object
	internal:
		CVanillaSwap (QL::Instruments::VanillaSwap::TypeEnum type, Double nominal, Cephei::QL::Times::ISchedule^ fixedSchedule, Double fixedRate, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Cephei::QL::Times::IDayCounter^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Cephei::QL::IPricingEngine^ QL_Pricer);
        CVanillaSwap (boost::shared_ptr<QuantLib::VanillaSwap>& childNative, Object^ owner);
        CVanillaSwap (QuantLib::VanillaSwap& childNative, Object^ owner);
        CVanillaSwap (CVanillaSwap^ copy);
        CVanillaSwap (PLATFORM::Type^ t);
#ifdef STRUCT
        CVanillaSwap (QuantLib::VanillaSwap childNative);
#endif       
#ifdef HANDLE
		CVanillaSwap (QuantLib::Handle<QuantLib::VanillaSwap>& childNative, Object^ owner);
		CVanillaSwap (QuantLib::Handle<QuantLib::VanillaSwap> childNative);
#endif
		virtual ~CVanillaSwap ();
		!CVanillaSwap ();

	internal:
		QuantLib::VanillaSwap& GetReference ();
		boost::shared_ptr<QuantLib::VanillaSwap>& GetShared ();
		QuantLib::VanillaSwap* GetPointer ();
        void SetVanillaSwap (boost::shared_ptr<QuantLib::VanillaSwap> native)
        {
            if (_ppVanillaSwap != NULL)
                delete _ppVanillaSwap;
            _ppVanillaSwap = new boost::shared_ptr<QuantLib::VanillaSwap> (native);
            SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::VanillaSwap>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Double FairRate 
        {
		    virtual Double get () ;
        }
        property Double FairSpread 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Times::IDayCounter^ FixedDayCount 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ FixedLeg 
        {
		    virtual Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Double FixedLegBPS 
        {
		    virtual Double get () ;
        }
        property Double FixedLegNPV 
        {
		    virtual Double get () ;
        }
        property Double FixedRate 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Times::ISchedule^ FixedSchedule 
        {
		    virtual Cephei::QL::Times::ISchedule^ get () ;
        }
        property Cephei::QL::Times::IDayCounter^ FloatingDayCount 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ FloatingLeg 
        {
		    virtual Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Double FloatingLegBPS 
        {
		    virtual Double get () ;
        }
        property Double FloatingLegNPV 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Times::ISchedule^ FloatingSchedule 
        {
		    virtual Cephei::QL::Times::ISchedule^ get () ;
        }
        property Cephei::QL::Indexes::IIborIndex^ IborIndex 
        {
		    virtual Cephei::QL::Indexes::IIborIndex^ get () ;
        }
        property Double Nominal 
        {
		    virtual Double get () ;
        }
        property QL::Times::BusinessDayConventionEnum PaymentConvention 
        {
		    virtual QL::Times::BusinessDayConventionEnum get () ;
        }
        property Double Spread 
        {
		    virtual Double get () ;
        }
        property QL::Instruments::VanillaSwap::TypeEnum Type 
        {
		    virtual QL::Instruments::VanillaSwap::TypeEnum get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Instruments::IVanillaSwap^>::typeid)]
	[FactoryFor(Cephei::QL::Instruments::IVanillaSwap::typeid)]
	[FactoryFor(Cephei::QL::Instruments::IVanillaSwap_Factory::typeid)]
	public ref class CVanillaSwap_Factory sealed : public IVanillaSwap_Factory
	{
	public:
        virtual IVanillaSwap^ Create (QL::Instruments::VanillaSwap::TypeEnum type, Double nominal, Cephei::QL::Times::ISchedule^ fixedSchedule, Double fixedRate, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Cephei::QL::Times::IDayCounter^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
